package com.vip.common.util;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadFactory;

/**
 * 线程工厂
 *
 * @author wgb
 * @date 2020/6/11 17:39
 */
@Slf4j
public class MyThreadFactory implements ThreadFactory {

    @Override
    public Thread newThread(Runnable r) {
        Thread newThread = new Thread(r);
        newThread.setName("Thread-" + System.currentTimeMillis());
        newThread.setUncaughtExceptionHandler((t, e) -> {
            log.info("线程执行异常：" + t.getName() + e.getMessage(), e);
        });
        return newThread;
    }
}
